collectgarbage("setpause", 110)
-- collectgarbage("setstepmul", 250)
collectgarbage("restart")
if ChatFrame1 then
	ChatFrame1:AddMessage("Tweaked garbage collector")
end

local last_count = collectgarbage("count")
local in_hook = false

local function hook(param, value)
	if in_hook then return end
	in_hook = true
	
	local count
	if param == nil or param == "collect" then
		last_count = collectgarbage("count")
		count = last_count
	else
		count = collectgarbage("count")
	end

	local f = ChatFrame1
	if param ~= "count" then
		f:AddMessage(string.format("CALL collectgarbage(%s, %s)", tostring(param), tostring(value)))
	end
	
	if (count + 1) < last_count then
		PlaySoundFile("Interface\\AddOns\\jerry\\gc.wav")
		f:AddMessage(string.format("Automatic garbage collection collected %3.2f Kb !", last_count - count))
	end
	last_count = count
	in_hook = false
end

hooksecurefunc("collectgarbage", hook)
